<template>
    <div class="app-container">
      <div class="container">
        <div class="main page page-list">
          <div class="head-container">
            <el-card shadow="never">
              <div class="search-bar">
                <el-form
                  :inline="true"
                  :model="searchModel"
                  size="mini"
                  class="demo-form-inline"
                >
                <el-form-item label="截止日期">
                  <el-date-picker
                    v-model="searchModel.day"
                    type="date"
                    value-format='yyyy-MM-dd'
                    placeholder="选择日期"
                  >
                  </el-date-picker>
                </el-form-item>

                  <el-form-item label="商户编号">
                    <el-input
                      v-model="searchModel.userId"
                      placeholder="商户编号"
                    />
                  </el-form-item>

                  
                
                  <el-form-item class="operations">
                    <el-button
                      type="primary"
                      @click="search"
                    >查询</el-button>
                    <el-button
                      type="default"
                      @click="reset"
                    >重置</el-button>
                  </el-form-item>
                </el-form>
              </div>
  
            </el-card>
          </div>
  
          <div class="sumBox">
            <div class="sumItem">
            <span class="m-t-8">总留存金额</span>
            <div class="sumdata1">
              <span>¥ {{ sumData ? sumData.moneyLeft : "0.00" }}</span>
            </div>
            <div>
                  <span class="m-r-8">昨日总留存金额:</span>
                <span>{{ sumData.beforeMoneyLeft }}</span>
                </div>
                <div>
                  <span class="m-r-8">留存变动金额:</span>
                  <span >{{ sumData.changeMoney }}</span>
                </div>
          </div>
          
          </div>
  
          <div class="data-list-wrap">
            <el-card shadow="never">
              <el-table
                v-loading="loading"
                :data="list"
                size="small"
                style="width: 100%;"
              >
              <el-table-column
                  prop="day"
                  label="日期"
                />
                
               
                <el-table-column
                  prop="userId"
                  label="商户编号"
                />

                <el-table-column label="账户历史留存">
                  <template slot-scope="scope">
                    {{ scope.row.moneyLeft }}
                  </template>
                </el-table-column>


              </el-table>
  
  
              <div class="paging-wrap">
                <el-pagination
                  :current-page="searchModel.pageNo"
                  :page-sizes="[10, 20, 50, 100]"
                  :page-size="searchModel.pagesize"
                  :total="searchModel.count"
                  layout="total, sizes, prev, pager, next, jumper"
                  @size-change="handleSizeChange"
                  @current-change="handleCurrentChange"
                />
              </div>
            </el-card>
          </div>
  
        </div>
      </div>
    </div>
  </template>
  
  <script>
  import { searchUserAccountMoneyLeftStat, sumUserAccountMoneyLeftStat } from '@/api/business'
  import moment from "moment";
  const defaultModel = {
    userId: null,
    day: moment().subtract(1, "d").format("YYYY-MM-DD"),
    pageNo: 1,
    pageSize: 10,
    count: 0
  }
  export default {
    components: {},
    data() {
      return {
        searchModel: _.cloneDeep(defaultModel),
        list: [],
        loading: false,
        curData: null,
        opLoading:false,
        extra:"",
        sumData: {
          moneyLeft: "0.00",
          beforeMoneyLeft: "0.00",
          changeMoney: "0.00"
        }
      }
    },
    mounted() {
      // 判断路由中是否有daily参数，如果有代表从日账单跳转过来
      const param = this.$route.query.from
      if (param === 'daily') {
        this.searchModel.maxAmount = 0
        this.searchModel.minAmount = ''
      }
      this.init()
    },
    methods: {
      search() {
        this.getList(1);
        this.sum();
      },

      sum() {
        let searchModel = _.cloneDeep(this.searchModel);
        sumUserAccountMoneyLeftStat(searchModel).then(resp=> {
          if(resp.success) {
            this.sumData = resp.data;
          }
        }).catch(err => console.log(err))
      },
  
      getList(pageNo) {
        var self = this;
        this.loading = true;
        if (pageNo != undefined) {
          this.searchModel.pageNo = pageNo;
        }
        let searchModel = _.cloneDeep(this.searchModel);
        searchUserAccountMoneyLeftStat(this.compileSearchModel(searchModel))
          .then((data) => {
            self.searchModel.count = data.count;
            self.list = data.data;
            self.extra = data.extra;
            self.loading = false;
          })
          .catch((err) => {});
      },

    
    
      reset() {
        this.searchModel = _.cloneDeep(defaultModel)
        this.getList(1)
      },
      compileSearchModel(searchModel) {
        searchModel.pageNo = searchModel.pageNo - 1

        return searchModel
      },
      // 修改分页
      handleSizeChange(val) {
        this.searchModel.pageSize = val
        this.getList(1)
      },
      // 修改页面
      handleCurrentChange(val) {
        this.getList(val)
      },
      init() {
        this.search();
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .sumBox {
    display: grid;
    grid-template-columns: repeat(4, 25%);
    padding: 0 2px;
    margin-bottom: 10px;
  }
  .sumItem {
      display: flex;
      flex-direction: column;
      justify-content: space-around;
      align-items: center;
      align-items: center;
      margin-right: 16px;
      height: 150px;
      padding: 16px;
      background-color: #fff;
      box-sizing: border-box;
      font-weight: 600;
  
      .sumdata {
        width: 100%;
        height: 100px;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        font-size: 20px;
        font-weight: 600;
      }
  
    }
  .substationGroup {
    margin-bottom: 16px;
    .substationItem {
      margin-right: 20px;
    }
  }
  </style>
  0